/**      
 * @file		strncpy_fix.cpp
 * @description		Demonstrates how to use strncpy() instead of 
 *			strcpy()
 * @course		CSCI 123 Section 00000
 * @assignment 
 * @date		mm/dd/yyyy
 * @author		Brad Rippe (00000000) brippe@fullcoll.edu
 * @version		1.0
 */
#include <iostream>
#include <cstring>
using namespace std;

/**
 * @return zero if the application executes successfully
 */
int main() {
	// cstrings require you to declare how many elements are
	// in the array. You do this by explicitly stating in the
	// brackets or by assigning the cstring a value when it is 
	// declared
	char cString1[] = "Please email my message to the class!";
	char cString2[38];		// notice the size is changed
	int cString1Size = 0;

	// get the size of cString1
	while(cString1[cString1Size] != '\0') cString1Size++;

	cout << "This application demonstrates how to copy cstrings\n";
	cout << "Remember we can't use the assignment operator, = to assign";
	cout << " cstrings values unless we use it when we declare the cstring\n";
	cout << "We'll use strncpy(destination, source, numOfChars) to copy cString1 to cString2\n";
	cout << "strncpy(cString2, cString1, size);\n";
	
	strncpy(cString2, cString1, cString1Size);
	cString2[37] = '\0'; // add the null or add one to the cString1Size in the previous statement

	cout << "cString1 = " << cString1 << endl;
	cout << "cString2 = " << cString2 << endl;

	return 0;
}

